﻿
@{
    ViewBag.Title = "站内信管理";
    Layout = "~/Views/Shared/_Layout_Content.cshtml";
}
@section styles
{
    <environment names="Development">
        <link href="~/css/plugins/jqgrid/ui.jqgrid.css" rel="stylesheet" />
    </environment>
    <environment names="Staging,Production">
        <link rel="stylesheet" href="~/css/grid.min.css" asp-append-version="true" />
    </environment>
}

<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>@ViewBag.Title</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="form-group">
                <button id="btnAdd" type="button" class="btn btn-primary " onclick="addModel()"><i class="fa fa-check"></i>&nbsp;发送站内信</button>
                <button id="btnDel" type="button" class="btn btn-danger " onclick="delData()">
                    <i class="fa fa-dedent"></i>&nbsp;&nbsp;<span class="bold">删除</span>
                </button>
            </div>

            <div class="form-group">
                <div class="input-group">
                    <input id="txtSearchKey" type="text" class="input form-control" placeholder="搜索关键字" />
                    <span class="input-group-btn">
                        <button id="btnSearch" class="btn btn btn-primary" type="button"> <i class="fa fa-search"></i> 搜索</button>
                    </span>
                </div>
            </div>

            <div class="jqGrid_wrapper">
                <table id="table_list"></table>
                <div id="pager_list"></div>
            </div>
        </div>
    </div>
</div>

@section scripts
{

    <environment names="Development">
        <script src="~/js/plugins/jqgrid/jquery.jqGrid.js"></script>
        <script src="~/js/plugins/jqgrid/i18n/grid.locale-cn.js"></script>
        <script src="~/js/jqgrid-list.js"></script>
        <script src="~/js/json2.js"></script>
        <script src="~/js/base.js"></script>
    </environment>
    <environment names="Staging,Production">
        <script src="~/js/grid.min.js" asp-append-version="true"></script>
    </environment>
    <script>
        function addModel() {
            $("#btnAdd").button("loading");
            window.location.href = "@Url.Action("Add")";
        }

        function delData() {//删除
            XPage.DelData("@Url.Action("Delete")");
        }

        function searchData() {//搜索
            var json = {
                keywords: $("#txtSearchKey").val()
            };
            XPage.Search(json);
        }
        function showDetails(messageId) {
            parent.layer.open({
                title: '详情',
                type: 2,
                content: '/message/detail/' + messageId,
                area: ['80%', '60%']
            });
        }
        $(document).ready(function() {
            var config = {
                title: '站内信列表',
                url: '@Url.Action("GetListWithPager")',
                colNames: ['主键', '标题','已读数/总量', '创建时间', '操作'],
                colModel: [
                    { name: 'id', index: 'id', width: 60, key: true, hidden: true },
                    { name: 'title', index: 'title', width: 200 },
                    {
                        name: 'Total', index: 'Total', width: 30,
                        formatter: function (cellValue, options, rowObject) {
                            return rowObject.readedNumber + " / " + rowObject.total;
                        }
                    },
                    { name: 'createDateTime', index: 'createDateTime', width: 60 },
                    {
                        name: 'createDateTime', index: 'createDateTime', width: 30,align:'center',
                        formatter: function (cellValue, options, rowObject) {
                            return '<a class="btn btn-primary btn-xs" onclick="showDetails(\'' + rowObject.id + '\')">详情</a>';
                        }
                    }
                ]
            };
            JucheapGrid.Load(config);
            $("#btnSearch").bind("click", searchData);
        });
    </script>
}
